#include "GameMethodPlayScene.h"

GameMethodPlayScene::GameMethodPlayScene(void)
{
}

GameMethodPlayScene::~GameMethodPlayScene(void)
{
}

bool GameMethodPlayScene::init()
{
	bool bRet = false;

	do 
	{
		CCLayer* pInfoLayer = GameMethodPlayInfoLayer::node();
		CC_BREAK_IF(!pInfoLayer);
		this->addChild(pInfoLayer, INFO_LAYER,INFO_LAYER);

		CCLayer* pMenuLayer = GameMethodMenuLayer::node();
		CC_BREAK_IF(!pMenuLayer);
		this->addChild(pMenuLayer, MENU_LAYER, MENU_LAYER);

		bRet = true;
	} while (0);

	return bRet;
}

GameMethodPlayInfoLayer::GameMethodPlayInfoLayer(void)
{
	m_fTime = 60.0F;
}

GameMethodPlayInfoLayer::~GameMethodPlayInfoLayer(void)
{

}

bool GameMethodPlayInfoLayer::init()
{
	bool bRet = false;

	do 
	{
		CCSize s = CCDirector::sharedDirector()->getWinSize();
		CCSprite* pScoreSprite = CCSprite::spriteWithFile("images/button/0001.png", CCRectMake(0, 1, 48, 51));
		CC_BREAK_IF(!pScoreSprite);
		pScoreSprite->setPosition(ccp(pScoreSprite->getContentSize().width/2+2, s.height-pScoreSprite->getContentSize().height/2));
		this->addChild(pScoreSprite, 1, pSpriteScore);

		CCLabelBMFont *pScorelabel = CCLabelBMFont::labelWithString("10", s_fontmenu);
		CC_BREAK_IF(!pScorelabel);
		pScorelabel->setPosition(ccp( pScoreSprite->getContentSize().width+5+pScorelabel->getContentSize().width/2, s.height - pScorelabel->getContentSize().height/2 -2));
		pScorelabel->setAnchorPoint( ccp(0.5f, 0.5f) );
		pScorelabel->setScale(0.6F);
		this->addChild(pScorelabel, 1, pLabelScore);

		char str[6] = {0};
		sprintf(str, "%2.2f", m_fTime);
		CCLabelBMFont *pTimelabel = CCLabelBMFont::labelWithString(str, s_fontmenu);
		CC_BREAK_IF(!pTimelabel);
		pTimelabel->setPosition(ccp(s.width - pTimelabel->getContentSize().width/2 - 2 , s.height - pTimelabel->getContentSize().height/2 -2));
		pTimelabel->setAnchorPoint( ccp(0.5f, 0.5f) );
		pTimelabel->setScale(0.6F);
		this->addChild(pTimelabel, 1, pLabelTime);

		bRet = true;

	} while (0);

	return bRet;
}

void GameMethodPlayInfoLayer::step(ccTime dt)
{
	m_fTime -= dt;	
	char str[6] = {0};
	sprintf(str, "%2.2f", m_fTime);
	CCLabelBMFont* label1 = (CCLabelBMFont*)getChildByTag(pLabelTime);
	if (m_fTime < 0.001)
	{
		m_fTime = 0.0F;
		label1->setString("0.0");
		unschedule( schedule_selector(GameMethodPlayInfoLayer::step) );
		return;
		//Game Over
	}
	label1->setString(str);

}

void GameMethodPlayInfoLayer::onEnter()
{
	TYLayer::onEnter();
	schedule( schedule_selector(GameMethodPlayInfoLayer::step));
}

void GameMethodPlayInfoLayer::onExit()
{
	TYLayer::onExit();
	if (m_fTime > 0.001)
	{
		unschedule( schedule_selector(GameMethodPlayInfoLayer::step) );
	}
}

GameMethodMenuLayer::GameMethodMenuLayer(void)
{
	bIsMenuClick = false;
}

GameMethodMenuLayer::~GameMethodMenuLayer(void)
{

}

bool GameMethodMenuLayer::init()
{
	bool bRet = false;

	do 
	{
		CCSize s = CCDirector::sharedDirector()->getWinSize();

		CCSprite* normalSprite = CCSprite::spriteWithFile("images/menu/0001.png");
		CC_BREAK_IF(!normalSprite);
		CCSprite* selectedSprite = CCSprite::spriteWithFile("images/menu/0001.png");
		CC_BREAK_IF(!selectedSprite);
		CCMenuItemSprite* pSpriteMenu = CCMenuItemSprite::itemFromNormalSprite(normalSprite, selectedSprite, this, menu_selector(GameMethodMenuLayer::MenuItemCallBack));
		CC_BREAK_IF(!pSpriteMenu);
		CCMenu* menu = CCMenu::menuWithItems(pSpriteMenu, NULL);
		CC_BREAK_IF(!menu);
		menu->setPosition(CCPointZero);
		pSpriteMenu->setPosition(ccp(s.width - pSpriteMenu->getContentSize().width / 2 , pSpriteMenu->getContentSize().height / 2 ));
		
		this->addChild(menu);

		bRet = true;

	} while (0);

	return bRet;
}

void GameMethodMenuLayer::MenuItemCallBack( CCObject* sender )
{
	bIsMenuClick = true;

	do 
	{
		GameMethodPlayeMsgBoxLayer* msgLayer = GameMethodPlayeMsgBoxLayer::node();
		CC_BREAK_IF(!msgLayer);
		CCDirector::sharedDirector()->getRunningScene()->addChild(msgLayer, MSGBOX_LAYER, MSGBOX_LAYER);

	} while (0);
		
	bIsMenuClick = false;
}


GameMethodPlayeMsgBoxLayer::GameMethodPlayeMsgBoxLayer( void )
{

}

GameMethodPlayeMsgBoxLayer::~GameMethodPlayeMsgBoxLayer( void )
{

}

bool GameMethodPlayeMsgBoxLayer::init()
{
	bool bRet = false;

	do 
	{
		CCSize s = CCDirector::sharedDirector()->getWinSize();

		CCSprite* backSprite = CCSprite::spriteWithFile("images/task/0002.png");
		CC_BREAK_IF(!backSprite);
		backSprite->setPosition(ccp(s.width / 2, s.height / 2));
		this->addChild(backSprite, 1);

		CCLabelBMFont* label = CCLabelBMFont::labelWithString("Go Back", s_fontmenu);
		CC_BREAK_IF(!label);
		CCMenuItemLabel* methodBackLabel = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(TYLayerMessageBox::MenuDoBack));
		CC_BREAK_IF(!methodBackLabel);

		CCMenu *menu = CCMenu::menuWithItems(methodBackLabel, NULL);
		CC_BREAK_IF(!menu);
		this->addChild(menu, 2);
		menu->setPosition(CCPointZero);
		methodBackLabel->setPosition(ccp(s.width /2 , s.height / 2));

		bRet = true;

	} while (0);

	return bRet;
}